<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 13.用函数封装一个数组的unshift方法

        //在数组前面添加一个或多个元素
        var arr = ["a", "b", "c"];
        //思路:
        //var a = 10;
        //var[0] = a;  //arr=[10;"b","c"]
        //arr[arr.length] = arr[2];//arr=["a","b","c","c"]
        //arr[2] = arr[1];//arr=["a","b","b","c"]
        //arr[1] = arr[0];//arr=["a","a","b","c"]
        //arr[0] =a; //arr=[10,"a","b","c"] 

        //for (vari=arr.length;i>0;i--) {
        //console.log(arr[i]);
        //arr[i] = arr[i-1];

        //}
        //arr[0] =a;

        //var arr1 =[10,20,30,40];

        //for(var k=arr1.length - 1 ; k>0;k--) {
        //     for(var i=arr,length;i>0;i++) {
        //arr[i] = arr[i-1];

        //}
        //arr[0] = arr1[k];
        //}


        function unshift(array) {
            //argument
            for (var k = argument.length - 1; k >= 1; k--) {
                for (var i = array.length; i > 0; i--) {
                    array[i] = array[i - 1]
                }
                array[0] = arguments[k];
            }
        }

    </script>
</body>

</html>